//
//  HYReleaseSelectView.m
//  HaiYue
//
//  Created by skyline on 2018/1/23.
//  Copyright © 2018年 skyline. All rights reserved.
//



#import "HYReleaseSelectView.h"
#import "HYReleaseSelectButton.h"
@interface HYReleaseSelectView()
@property (nonatomic, strong) HYView *backView;
@end

@implementation HYReleaseSelectView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.backView.alpha = 0.5;
        [self setupSubViews];
    }
    return self;
}

- (HYView *)backView
{
    if (!_backView)
    {
       _backView = [[HYView alloc] initWithColor:[UIColor blackColor]];
        [self addSubview:_backView];
        [_backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsZero);
        }];
    }
    return _backView;
}

- (void)setupSubViews
{
    NSArray *titles = @[@"最新发布", @"价格最低", @"价格最高"];
    for (int i = 0; i < 3; i ++)
    {
       HYReleaseSelectButton *button = [[HYReleaseSelectButton alloc] initWithTitle:titles[i]];
        button.tag = 200 + i;
        [button addTarget:self action:@selector(actionForHYReleaseSelectButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button];
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(ButtonHeight * i);
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.height.mas_equalTo(ButtonHeight);
        }];
        
        if (i < 2)
        {
           HYView *line = [[HYView alloc] initWithColor:LINE_COLOR];
            [self addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(button.mas_bottom).with.offset(-0.5);
                make.left.equalTo(self);
                make.right.equalTo(self);
                make.height.mas_equalTo(1.0);
            }];
        }
    }
}

- (void)actionForHYReleaseSelectButton:(HYReleaseSelectButton *)sender
{
    self.hidden = YES;
    if (self.delegate && [self.delegate respondsToSelector:@selector(methodForHYReleaseSelectViewDelegateWithTitle:)])
    {
        [self.delegate methodForHYReleaseSelectViewDelegateWithTitle:sender.title];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
